{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    },
    "accelerator": "GPU",
    "gpuClass": "standard"
  },
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "**Edge-IIoTset Dataset Exploration and Preprocessing**"
      ],
      "metadata": {
        "id": "uZAiHHAvLTjC"
      }
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "SIyRjS9gyubE"
      },
      "outputs": [],
      "source": [
        "import itertools\n",
        "import numpy as np\n",
        "import pandas as pd\n",
        "import seaborn as sns\n",
        "import matplotlib.pyplot as plt\n",
        "\n",
        "sns.set() # set seaborn to default settings"
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "**Import the data into a pandas data-frame and inspect it’s properties.**"
      ],
      "metadata": {
        "id": "hWapfr0H_uC6"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "df = pd.read_csv('/content/drive/MyDrive/DNN-EdgeIIoT-dataset.csv', low_memory=False) \n",
        "df.shape # (2219201, 63)\n",
        "df.head()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 386
        },
        "id": "H0NNFFUIy9bT",
        "outputId": "3fad8fc8-2bb7-463f-9b30-87dd20f9ce24"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "                  frame.time    ip.src_host    ip.dst_host arp.dst.proto_ipv4  \\\n",
              "0   2021 11:44:10.081753000   192.168.0.128  192.168.0.101                  0   \n",
              "1   2021 11:44:10.162218000   192.168.0.101  192.168.0.128                  0   \n",
              "2   2021 11:44:10.162271000   192.168.0.128  192.168.0.101                  0   \n",
              "3   2021 11:44:10.162641000   192.168.0.128  192.168.0.101                  0   \n",
              "4   2021 11:44:10.166132000   192.168.0.101  192.168.0.128                  0   \n",
              "\n",
              "   arp.opcode  arp.hw.size arp.src.proto_ipv4  icmp.checksum  icmp.seq_le  \\\n",
              "0         0.0          0.0                  0            0.0          0.0   \n",
              "1         0.0          0.0                  0            0.0          0.0   \n",
              "2         0.0          0.0                  0            0.0          0.0   \n",
              "3         0.0          0.0                  0            0.0          0.0   \n",
              "4         0.0          0.0                  0            0.0          0.0   \n",
              "\n",
              "   icmp.transmit_timestamp  ...  mqtt.proto_len mqtt.protoname  \\\n",
              "0                      0.0  ...             0.0              0   \n",
              "1                      0.0  ...             4.0           MQTT   \n",
              "2                      0.0  ...             0.0              0   \n",
              "3                      0.0  ...             0.0              0   \n",
              "4                      0.0  ...             0.0              0   \n",
              "\n",
              "                 mqtt.topic mqtt.topic_len mqtt.ver mbtcp.len mbtcp.trans_id  \\\n",
              "0                         0            0.0      0.0       0.0            0.0   \n",
              "1                         0            0.0      4.0       0.0            0.0   \n",
              "2                         0            0.0      0.0       0.0            0.0   \n",
              "3                         0            0.0      0.0       0.0            0.0   \n",
              "4  Temperature_and_Humidity           24.0      0.0       0.0            0.0   \n",
              "\n",
              "  mbtcp.unit_id  Attack_label  Attack_type  \n",
              "0           0.0             0       Normal  \n",
              "1           0.0             0       Normal  \n",
              "2           0.0             0       Normal  \n",
              "3           0.0             0       Normal  \n",
              "4           0.0             0       Normal  \n",
              "\n",
              "[5 rows x 63 columns]"
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-36539192-cac2-4404-8983-27c1266fc09b\">\n",
              "    <div class=\"colab-df-container\">\n",
              "      <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>frame.time</th>\n",
              "      <th>ip.src_host</th>\n",
              "      <th>ip.dst_host</th>\n",
              "      <th>arp.dst.proto_ipv4</th>\n",
              "      <th>arp.opcode</th>\n",
              "      <th>arp.hw.size</th>\n",
              "      <th>arp.src.proto_ipv4</th>\n",
              "      <th>icmp.checksum</th>\n",
              "      <th>icmp.seq_le</th>\n",
              "      <th>icmp.transmit_timestamp</th>\n",
              "      <th>...</th>\n",
              "      <th>mqtt.proto_len</th>\n",
              "      <th>mqtt.protoname</th>\n",
              "      <th>mqtt.topic</th>\n",
              "      <th>mqtt.topic_len</th>\n",
              "      <th>mqtt.ver</th>\n",
              "      <th>mbtcp.len</th>\n",
              "      <th>mbtcp.trans_id</th>\n",
              "      <th>mbtcp.unit_id</th>\n",
              "      <th>Attack_label</th>\n",
              "      <th>Attack_type</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>2021 11:44:10.081753000</td>\n",
              "      <td>192.168.0.128</td>\n",
              "      <td>192.168.0.101</td>\n",
              "      <td>0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>...</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>Normal</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>2021 11:44:10.162218000</td>\n",
              "      <td>192.168.0.101</td>\n",
              "      <td>192.168.0.128</td>\n",
              "      <td>0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>...</td>\n",
              "      <td>4.0</td>\n",
              "      <td>MQTT</td>\n",
              "      <td>0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>4.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>Normal</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>2021 11:44:10.162271000</td>\n",
              "      <td>192.168.0.128</td>\n",
              "      <td>192.168.0.101</td>\n",
              "      <td>0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>...</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>Normal</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>2021 11:44:10.162641000</td>\n",
              "      <td>192.168.0.128</td>\n",
              "      <td>192.168.0.101</td>\n",
              "      <td>0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>...</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>Normal</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>2021 11:44:10.166132000</td>\n",
              "      <td>192.168.0.101</td>\n",
              "      <td>192.168.0.128</td>\n",
              "      <td>0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>...</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>Temperature_and_Humidity</td>\n",
              "      <td>24.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>Normal</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "<p>5 rows × 63 columns</p>\n",
              "</div>\n",
              "      <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-36539192-cac2-4404-8983-27c1266fc09b')\"\n",
              "              title=\"Convert this dataframe to an interactive table.\"\n",
              "              style=\"display:none;\">\n",
              "        \n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "       width=\"24px\">\n",
              "    <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
              "    <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
              "  </svg>\n",
              "      </button>\n",
              "      \n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      flex-wrap:wrap;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "      <script>\n",
              "        const buttonEl =\n",
              "          document.querySelector('#df-36539192-cac2-4404-8983-27c1266fc09b button.colab-df-convert');\n",
              "        buttonEl.style.display =\n",
              "          google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "        async function convertToInteractive(key) {\n",
              "          const element = document.querySelector('#df-36539192-cac2-4404-8983-27c1266fc09b');\n",
              "          const dataTable =\n",
              "            await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                     [key], {});\n",
              "          if (!dataTable) return;\n",
              "\n",
              "          const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "            '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "            + ' to learn more about interactive tables.';\n",
              "          element.innerHTML = '';\n",
              "          dataTable['output_type'] = 'display_data';\n",
              "          await google.colab.output.renderOutput(dataTable, element);\n",
              "          const docLink = document.createElement('div');\n",
              "          docLink.innerHTML = docLinkHtml;\n",
              "          element.appendChild(docLink);\n",
              "        }\n",
              "      </script>\n",
              "    </div>\n",
              "  </div>\n",
              "  "
            ]
          },
          "metadata": {},
          "execution_count": 2
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "**The data is in tabular form, with 2219201 entries, each having 63 distinct attributes.**"
      ],
      "metadata": {
        "id": "WKRT9zqjBiNr"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# let's list all the columns\n",
        "columns = list(df.columns)\n",
        "columns\n"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "CxtRbn8bB1YT",
        "outputId": "7835b00f-6f1a-45a7-f768-5c50c70ee8bb"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "['frame.time',\n",
              " 'ip.src_host',\n",
              " 'ip.dst_host',\n",
              " 'arp.dst.proto_ipv4',\n",
              " 'arp.opcode',\n",
              " 'arp.hw.size',\n",
              " 'arp.src.proto_ipv4',\n",
              " 'icmp.checksum',\n",
              " 'icmp.seq_le',\n",
              " 'icmp.transmit_timestamp',\n",
              " 'icmp.unused',\n",
              " 'http.file_data',\n",
              " 'http.content_length',\n",
              " 'http.request.uri.query',\n",
              " 'http.request.method',\n",
              " 'http.referer',\n",
              " 'http.request.full_uri',\n",
              " 'http.request.version',\n",
              " 'http.response',\n",
              " 'http.tls_port',\n",
              " 'tcp.ack',\n",
              " 'tcp.ack_raw',\n",
              " 'tcp.checksum',\n",
              " 'tcp.connection.fin',\n",
              " 'tcp.connection.rst',\n",
              " 'tcp.connection.syn',\n",
              " 'tcp.connection.synack',\n",
              " 'tcp.dstport',\n",
              " 'tcp.flags',\n",
              " 'tcp.flags.ack',\n",
              " 'tcp.len',\n",
              " 'tcp.options',\n",
              " 'tcp.payload',\n",
              " 'tcp.seq',\n",
              " 'tcp.srcport',\n",
              " 'udp.port',\n",
              " 'udp.stream',\n",
              " 'udp.time_delta',\n",
              " 'dns.qry.name',\n",
              " 'dns.qry.name.len',\n",
              " 'dns.qry.qu',\n",
              " 'dns.qry.type',\n",
              " 'dns.retransmission',\n",
              " 'dns.retransmit_request',\n",
              " 'dns.retransmit_request_in',\n",
              " 'mqtt.conack.flags',\n",
              " 'mqtt.conflag.cleansess',\n",
              " 'mqtt.conflags',\n",
              " 'mqtt.hdrflags',\n",
              " 'mqtt.len',\n",
              " 'mqtt.msg_decoded_as',\n",
              " 'mqtt.msg',\n",
              " 'mqtt.msgtype',\n",
              " 'mqtt.proto_len',\n",
              " 'mqtt.protoname',\n",
              " 'mqtt.topic',\n",
              " 'mqtt.topic_len',\n",
              " 'mqtt.ver',\n",
              " 'mbtcp.len',\n",
              " 'mbtcp.trans_id',\n",
              " 'mbtcp.unit_id',\n",
              " 'Attack_label',\n",
              " 'Attack_type']"
            ]
          },
          "metadata": {},
          "execution_count": 3
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "**Information About Data**"
      ],
      "metadata": {
        "id": "4PMzLC5xCE2D"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "df.info()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "YTWEK6OLCI4r",
        "outputId": "aa611d6d-a6f6-4d2e-f178-cdf6b8bef739"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "<class 'pandas.core.frame.DataFrame'>\n",
            "RangeIndex: 2219201 entries, 0 to 2219200\n",
            "Data columns (total 63 columns):\n",
            " #   Column                     Dtype  \n",
            "---  ------                     -----  \n",
            " 0   frame.time                 object \n",
            " 1   ip.src_host                object \n",
            " 2   ip.dst_host                object \n",
            " 3   arp.dst.proto_ipv4         object \n",
            " 4   arp.opcode                 float64\n",
            " 5   arp.hw.size                float64\n",
            " 6   arp.src.proto_ipv4         object \n",
            " 7   icmp.checksum              float64\n",
            " 8   icmp.seq_le                float64\n",
            " 9   icmp.transmit_timestamp    float64\n",
            " 10  icmp.unused                float64\n",
            " 11  http.file_data             object \n",
            " 12  http.content_length        float64\n",
            " 13  http.request.uri.query     object \n",
            " 14  http.request.method        object \n",
            " 15  http.referer               object \n",
            " 16  http.request.full_uri      object \n",
            " 17  http.request.version       object \n",
            " 18  http.response              float64\n",
            " 19  http.tls_port              float64\n",
            " 20  tcp.ack                    float64\n",
            " 21  tcp.ack_raw                float64\n",
            " 22  tcp.checksum               float64\n",
            " 23  tcp.connection.fin         float64\n",
            " 24  tcp.connection.rst         float64\n",
            " 25  tcp.connection.syn         float64\n",
            " 26  tcp.connection.synack      float64\n",
            " 27  tcp.dstport                float64\n",
            " 28  tcp.flags                  float64\n",
            " 29  tcp.flags.ack              float64\n",
            " 30  tcp.len                    float64\n",
            " 31  tcp.options                object \n",
            " 32  tcp.payload                object \n",
            " 33  tcp.seq                    float64\n",
            " 34  tcp.srcport                object \n",
            " 35  udp.port                   float64\n",
            " 36  udp.stream                 float64\n",
            " 37  udp.time_delta             float64\n",
            " 38  dns.qry.name               float64\n",
            " 39  dns.qry.name.len           object \n",
            " 40  dns.qry.qu                 float64\n",
            " 41  dns.qry.type               float64\n",
            " 42  dns.retransmission         float64\n",
            " 43  dns.retransmit_request     float64\n",
            " 44  dns.retransmit_request_in  float64\n",
            " 45  mqtt.conack.flags          object \n",
            " 46  mqtt.conflag.cleansess     float64\n",
            " 47  mqtt.conflags              float64\n",
            " 48  mqtt.hdrflags              float64\n",
            " 49  mqtt.len                   float64\n",
            " 50  mqtt.msg_decoded_as        float64\n",
            " 51  mqtt.msg                   object \n",
            " 52  mqtt.msgtype               float64\n",
            " 53  mqtt.proto_len             float64\n",
            " 54  mqtt.protoname             object \n",
            " 55  mqtt.topic                 object \n",
            " 56  mqtt.topic_len             float64\n",
            " 57  mqtt.ver                   float64\n",
            " 58  mbtcp.len                  float64\n",
            " 59  mbtcp.trans_id             float64\n",
            " 60  mbtcp.unit_id              float64\n",
            " 61  Attack_label               int64  \n",
            " 62  Attack_type                object \n",
            "dtypes: float64(42), int64(1), object(20)\n",
            "memory usage: 1.0+ GB\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "**Let’s see how many unique values are there in each column.**"
      ],
      "metadata": {
        "id": "Z8nsEfleCb9m"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "df.nunique(axis=0)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "1VpMNTiPCfLz",
        "outputId": "5fdfe463-8735-4647-f10e-254c4fdf258a"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "frame.time            2206364\n",
              "ip.src_host            137167\n",
              "ip.dst_host             52425\n",
              "arp.dst.proto_ipv4          9\n",
              "arp.opcode                  3\n",
              "                       ...   \n",
              "mbtcp.len                   8\n",
              "mbtcp.trans_id            151\n",
              "mbtcp.unit_id               6\n",
              "Attack_label                2\n",
              "Attack_type                15\n",
              "Length: 63, dtype: int64"
            ]
          },
          "metadata": {},
          "execution_count": 5
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "**Now, inspect for NaNs in the data.**"
      ],
      "metadata": {
        "id": "ZyTHfhvpC-Bb"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "df.isna().sum()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "4Pwq4oy2DAab",
        "outputId": "4d8fe6cc-9f7b-4cee-ea98-dcd9c89a9d07"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "frame.time            0\n",
              "ip.src_host           0\n",
              "ip.dst_host           0\n",
              "arp.dst.proto_ipv4    0\n",
              "arp.opcode            0\n",
              "                     ..\n",
              "mbtcp.len             0\n",
              "mbtcp.trans_id        0\n",
              "mbtcp.unit_id         0\n",
              "Attack_label          0\n",
              "Attack_type           0\n",
              "Length: 63, dtype: int64"
            ]
          },
          "metadata": {},
          "execution_count": 6
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "df.isnull().values.any()   #No null values in dataset"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "22sZ_CXTDJHT",
        "outputId": "5b41e815-ddc4-41df-ee3d-3b1c14ba4145"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "False"
            ]
          },
          "metadata": {},
          "execution_count": 7
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "**Let’s see how many duplicate entries are there and drop them if there are any.**"
      ],
      "metadata": {
        "id": "Gp5t4lNsDYDD"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# find total duplicate entries and drop them if any\n",
        "print(f'Total duplicate rows: {df.duplicated().sum()}')"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "YCDEUoUeDZq0",
        "outputId": "43d916ff-6b52-4fa8-800c-ad9f936f8238"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Total duplicate rows: 815\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# drop duplicate rows if any\n",
        "df = df[~df.duplicated()]"
      ],
      "metadata": {
        "id": "XE81NMAbDnc6"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "df.shape"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "pgrA--aCDvmL",
        "outputId": "98637678-73b1-41c8-8a8a-ccb54e9991c9"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "(2218386, 63)"
            ]
          },
          "metadata": {},
          "execution_count": 10
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "print(f'total duplicate rows: {df.duplicated().sum()}')"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "HoT6bowDEAQD",
        "outputId": "43aced69-5f0e-43c9-a85d-e424d1e99863"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "total duplicate rows: 0\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "df.head()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 386
        },
        "id": "_2Zw-shfENOo",
        "outputId": "66ff1343-431e-4d29-fbb9-9d2d2886ce66"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "                  frame.time    ip.src_host    ip.dst_host arp.dst.proto_ipv4  \\\n",
              "0   2021 11:44:10.081753000   192.168.0.128  192.168.0.101                  0   \n",
              "1   2021 11:44:10.162218000   192.168.0.101  192.168.0.128                  0   \n",
              "2   2021 11:44:10.162271000   192.168.0.128  192.168.0.101                  0   \n",
              "3   2021 11:44:10.162641000   192.168.0.128  192.168.0.101                  0   \n",
              "4   2021 11:44:10.166132000   192.168.0.101  192.168.0.128                  0   \n",
              "\n",
              "   arp.opcode  arp.hw.size arp.src.proto_ipv4  icmp.checksum  icmp.seq_le  \\\n",
              "0         0.0          0.0                  0            0.0          0.0   \n",
              "1         0.0          0.0                  0            0.0          0.0   \n",
              "2         0.0          0.0                  0            0.0          0.0   \n",
              "3         0.0          0.0                  0            0.0          0.0   \n",
              "4         0.0          0.0                  0            0.0          0.0   \n",
              "\n",
              "   icmp.transmit_timestamp  ...  mqtt.proto_len mqtt.protoname  \\\n",
              "0                      0.0  ...             0.0              0   \n",
              "1                      0.0  ...             4.0           MQTT   \n",
              "2                      0.0  ...             0.0              0   \n",
              "3                      0.0  ...             0.0              0   \n",
              "4                      0.0  ...             0.0              0   \n",
              "\n",
              "                 mqtt.topic mqtt.topic_len mqtt.ver mbtcp.len mbtcp.trans_id  \\\n",
              "0                         0            0.0      0.0       0.0            0.0   \n",
              "1                         0            0.0      4.0       0.0            0.0   \n",
              "2                         0            0.0      0.0       0.0            0.0   \n",
              "3                         0            0.0      0.0       0.0            0.0   \n",
              "4  Temperature_and_Humidity           24.0      0.0       0.0            0.0   \n",
              "\n",
              "  mbtcp.unit_id  Attack_label  Attack_type  \n",
              "0           0.0             0       Normal  \n",
              "1           0.0             0       Normal  \n",
              "2           0.0             0       Normal  \n",
              "3           0.0             0       Normal  \n",
              "4           0.0             0       Normal  \n",
              "\n",
              "[5 rows x 63 columns]"
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-1a585a86-e75d-460a-ac62-8a371eb2dcf9\">\n",
              "    <div class=\"colab-df-container\">\n",
              "      <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>frame.time</th>\n",
              "      <th>ip.src_host</th>\n",
              "      <th>ip.dst_host</th>\n",
              "      <th>arp.dst.proto_ipv4</th>\n",
              "      <th>arp.opcode</th>\n",
              "      <th>arp.hw.size</th>\n",
              "      <th>arp.src.proto_ipv4</th>\n",
              "      <th>icmp.checksum</th>\n",
              "      <th>icmp.seq_le</th>\n",
              "      <th>icmp.transmit_timestamp</th>\n",
              "      <th>...</th>\n",
              "      <th>mqtt.proto_len</th>\n",
              "      <th>mqtt.protoname</th>\n",
              "      <th>mqtt.topic</th>\n",
              "      <th>mqtt.topic_len</th>\n",
              "      <th>mqtt.ver</th>\n",
              "      <th>mbtcp.len</th>\n",
              "      <th>mbtcp.trans_id</th>\n",
              "      <th>mbtcp.unit_id</th>\n",
              "      <th>Attack_label</th>\n",
              "      <th>Attack_type</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>2021 11:44:10.081753000</td>\n",
              "      <td>192.168.0.128</td>\n",
              "      <td>192.168.0.101</td>\n",
              "      <td>0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>...</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>Normal</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>2021 11:44:10.162218000</td>\n",
              "      <td>192.168.0.101</td>\n",
              "      <td>192.168.0.128</td>\n",
              "      <td>0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>...</td>\n",
              "      <td>4.0</td>\n",
              "      <td>MQTT</td>\n",
              "      <td>0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>4.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>Normal</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>2021 11:44:10.162271000</td>\n",
              "      <td>192.168.0.128</td>\n",
              "      <td>192.168.0.101</td>\n",
              "      <td>0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>...</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>Normal</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>2021 11:44:10.162641000</td>\n",
              "      <td>192.168.0.128</td>\n",
              "      <td>192.168.0.101</td>\n",
              "      <td>0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>...</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>Normal</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>2021 11:44:10.166132000</td>\n",
              "      <td>192.168.0.101</td>\n",
              "      <td>192.168.0.128</td>\n",
              "      <td>0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>...</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>Temperature_and_Humidity</td>\n",
              "      <td>24.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>Normal</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "<p>5 rows × 63 columns</p>\n",
              "</div>\n",
              "      <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-1a585a86-e75d-460a-ac62-8a371eb2dcf9')\"\n",
              "              title=\"Convert this dataframe to an interactive table.\"\n",
              "              style=\"display:none;\">\n",
              "        \n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "       width=\"24px\">\n",
              "    <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
              "    <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
              "  </svg>\n",
              "      </button>\n",
              "      \n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      flex-wrap:wrap;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "      <script>\n",
              "        const buttonEl =\n",
              "          document.querySelector('#df-1a585a86-e75d-460a-ac62-8a371eb2dcf9 button.colab-df-convert');\n",
              "        buttonEl.style.display =\n",
              "          google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "        async function convertToInteractive(key) {\n",
              "          const element = document.querySelector('#df-1a585a86-e75d-460a-ac62-8a371eb2dcf9');\n",
              "          const dataTable =\n",
              "            await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                     [key], {});\n",
              "          if (!dataTable) return;\n",
              "\n",
              "          const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "            '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "            + ' to learn more about interactive tables.';\n",
              "          element.innerHTML = '';\n",
              "          dataTable['output_type'] = 'display_data';\n",
              "          await google.colab.output.renderOutput(dataTable, element);\n",
              "          const docLink = document.createElement('div');\n",
              "          docLink.innerHTML = docLinkHtml;\n",
              "          element.appendChild(docLink);\n",
              "        }\n",
              "      </script>\n",
              "    </div>\n",
              "  </div>\n",
              "  "
            ]
          },
          "metadata": {},
          "execution_count": 12
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "**Remove insignificant columns from data frame**"
      ],
      "metadata": {
        "id": "NJr2qK_5EqnE"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "from sklearn.utils import shuffle\n",
        "drop_columns = [\"frame.time\", \"ip.src_host\", \"ip.dst_host\", \"arp.src.proto_ipv4\",\"arp.dst.proto_ipv4\", \n",
        "                \"http.file_data\",\"http.request.full_uri\",\"icmp.transmit_timestamp\",\n",
        "                \"http.request.uri.query\", \"tcp.options\",\"tcp.payload\",\"tcp.srcport\",\n",
        "                \"tcp.dstport\", \"udp.port\", \"mqtt.msg\", \"Attack_label\"]\n",
        "\n",
        "df.drop(drop_columns, axis=1, inplace=True)\n",
        "df.dropna(axis=0, how='any', inplace=True)\n",
        "df.drop_duplicates(subset=None, keep=\"first\", inplace=True)\n",
        "df = shuffle(df)\n",
        "df.isna().sum()\n",
        "df.head()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 300
        },
        "id": "sKp2BfVB0Ao8",
        "outputId": "a729a1ce-d02d-4187-bc5b-2263d2fe8ab5"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "         arp.opcode  arp.hw.size  icmp.checksum  icmp.seq_le  icmp.unused  \\\n",
              "1860485         0.0          0.0            0.0          0.0          0.0   \n",
              "1526476         0.0          0.0            0.0          0.0          0.0   \n",
              "1796404         0.0          0.0            0.0          0.0          0.0   \n",
              "143399          0.0          0.0            0.0          0.0          0.0   \n",
              "859515          0.0          0.0            0.0          0.0          0.0   \n",
              "\n",
              "         http.content_length http.request.method http.referer  \\\n",
              "1860485                  0.0                   0          0.0   \n",
              "1526476                  0.0                 0.0          0.0   \n",
              "1796404                  0.0                 0.0          0.0   \n",
              "143399                   0.0                 0.0          0.0   \n",
              "859515                   0.0                 0.0          0.0   \n",
              "\n",
              "        http.request.version  http.response  ...  mqtt.msgtype  \\\n",
              "1860485                    0            0.0  ...           0.0   \n",
              "1526476                  0.0            0.0  ...           0.0   \n",
              "1796404                  0.0            0.0  ...           0.0   \n",
              "143399                   0.0            0.0  ...           0.0   \n",
              "859515                   0.0            0.0  ...           0.0   \n",
              "\n",
              "         mqtt.proto_len  mqtt.protoname  mqtt.topic  mqtt.topic_len  mqtt.ver  \\\n",
              "1860485             0.0             0.0         0.0             0.0       0.0   \n",
              "1526476             0.0               0           0             0.0       0.0   \n",
              "1796404             0.0             0.0         0.0             0.0       0.0   \n",
              "143399              0.0               0           0             0.0       0.0   \n",
              "859515              0.0               0           0             0.0       0.0   \n",
              "\n",
              "         mbtcp.len  mbtcp.trans_id  mbtcp.unit_id  Attack_type  \n",
              "1860485        0.0             0.0            0.0     Password  \n",
              "1526476        0.0             0.0            0.0       Normal  \n",
              "1796404        0.0             0.0            0.0     DDoS_TCP  \n",
              "143399         0.0             0.0            0.0       Normal  \n",
              "859515         0.0             0.0            0.0       Normal  \n",
              "\n",
              "[5 rows x 47 columns]"
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-5ab40698-ad55-4222-81cd-32995eedd29e\">\n",
              "    <div class=\"colab-df-container\">\n",
              "      <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>arp.opcode</th>\n",
              "      <th>arp.hw.size</th>\n",
              "      <th>icmp.checksum</th>\n",
              "      <th>icmp.seq_le</th>\n",
              "      <th>icmp.unused</th>\n",
              "      <th>http.content_length</th>\n",
              "      <th>http.request.method</th>\n",
              "      <th>http.referer</th>\n",
              "      <th>http.request.version</th>\n",
              "      <th>http.response</th>\n",
              "      <th>...</th>\n",
              "      <th>mqtt.msgtype</th>\n",
              "      <th>mqtt.proto_len</th>\n",
              "      <th>mqtt.protoname</th>\n",
              "      <th>mqtt.topic</th>\n",
              "      <th>mqtt.topic_len</th>\n",
              "      <th>mqtt.ver</th>\n",
              "      <th>mbtcp.len</th>\n",
              "      <th>mbtcp.trans_id</th>\n",
              "      <th>mbtcp.unit_id</th>\n",
              "      <th>Attack_type</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>1860485</th>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>...</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>Password</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1526476</th>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>...</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>Normal</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1796404</th>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>...</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>DDoS_TCP</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>143399</th>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>...</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>Normal</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>859515</th>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>...</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>Normal</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "<p>5 rows × 47 columns</p>\n",
              "</div>\n",
              "      <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-5ab40698-ad55-4222-81cd-32995eedd29e')\"\n",
              "              title=\"Convert this dataframe to an interactive table.\"\n",
              "              style=\"display:none;\">\n",
              "        \n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "       width=\"24px\">\n",
              "    <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
              "    <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
              "  </svg>\n",
              "      </button>\n",
              "      \n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      flex-wrap:wrap;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "      <script>\n",
              "        const buttonEl =\n",
              "          document.querySelector('#df-5ab40698-ad55-4222-81cd-32995eedd29e button.colab-df-convert');\n",
              "        buttonEl.style.display =\n",
              "          google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "        async function convertToInteractive(key) {\n",
              "          const element = document.querySelector('#df-5ab40698-ad55-4222-81cd-32995eedd29e');\n",
              "          const dataTable =\n",
              "            await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                     [key], {});\n",
              "          if (!dataTable) return;\n",
              "\n",
              "          const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "            '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "            + ' to learn more about interactive tables.';\n",
              "          element.innerHTML = '';\n",
              "          dataTable['output_type'] = 'display_data';\n",
              "          await google.colab.output.renderOutput(dataTable, element);\n",
              "          const docLink = document.createElement('div');\n",
              "          docLink.innerHTML = docLinkHtml;\n",
              "          element.appendChild(docLink);\n",
              "        }\n",
              "      </script>\n",
              "    </div>\n",
              "  </div>\n",
              "  "
            ]
          },
          "metadata": {},
          "execution_count": 13
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "df.shape"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "j1PQYOi90Jrl",
        "outputId": "cfd59eba-e5c9-4798-bc4d-b0a9f0fbb5b4"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "(1909671, 47)"
            ]
          },
          "metadata": {},
          "execution_count": 14
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "df.info()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "FZZmaXbjGKW7",
        "outputId": "61a3a0c5-4b39-4404-fe2b-7d346782f87e"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "<class 'pandas.core.frame.DataFrame'>\n",
            "Int64Index: 1909671 entries, 1860485 to 1293281\n",
            "Data columns (total 47 columns):\n",
            " #   Column                     Dtype  \n",
            "---  ------                     -----  \n",
            " 0   arp.opcode                 float64\n",
            " 1   arp.hw.size                float64\n",
            " 2   icmp.checksum              float64\n",
            " 3   icmp.seq_le                float64\n",
            " 4   icmp.unused                float64\n",
            " 5   http.content_length        float64\n",
            " 6   http.request.method        object \n",
            " 7   http.referer               object \n",
            " 8   http.request.version       object \n",
            " 9   http.response              float64\n",
            " 10  http.tls_port              float64\n",
            " 11  tcp.ack                    float64\n",
            " 12  tcp.ack_raw                float64\n",
            " 13  tcp.checksum               float64\n",
            " 14  tcp.connection.fin         float64\n",
            " 15  tcp.connection.rst         float64\n",
            " 16  tcp.connection.syn         float64\n",
            " 17  tcp.connection.synack      float64\n",
            " 18  tcp.flags                  float64\n",
            " 19  tcp.flags.ack              float64\n",
            " 20  tcp.len                    float64\n",
            " 21  tcp.seq                    float64\n",
            " 22  udp.stream                 float64\n",
            " 23  udp.time_delta             float64\n",
            " 24  dns.qry.name               float64\n",
            " 25  dns.qry.name.len           object \n",
            " 26  dns.qry.qu                 float64\n",
            " 27  dns.qry.type               float64\n",
            " 28  dns.retransmission         float64\n",
            " 29  dns.retransmit_request     float64\n",
            " 30  dns.retransmit_request_in  float64\n",
            " 31  mqtt.conack.flags          object \n",
            " 32  mqtt.conflag.cleansess     float64\n",
            " 33  mqtt.conflags              float64\n",
            " 34  mqtt.hdrflags              float64\n",
            " 35  mqtt.len                   float64\n",
            " 36  mqtt.msg_decoded_as        float64\n",
            " 37  mqtt.msgtype               float64\n",
            " 38  mqtt.proto_len             float64\n",
            " 39  mqtt.protoname             object \n",
            " 40  mqtt.topic                 object \n",
            " 41  mqtt.topic_len             float64\n",
            " 42  mqtt.ver                   float64\n",
            " 43  mbtcp.len                  float64\n",
            " 44  mbtcp.trans_id             float64\n",
            " 45  mbtcp.unit_id              float64\n",
            " 46  Attack_type                object \n",
            "dtypes: float64(39), object(8)\n",
            "memory usage: 699.3+ MB\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "**Visulalize the colums with objects.**"
      ],
      "metadata": {
        "id": "NkgFe2haJDZk"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "df['http.request.method'].value_counts()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "rccLYRn9HEc8",
        "outputId": "4c1f4fae-f6b3-416e-aec1-021004d349b8"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "0.0         1658469\n",
              "0            219116\n",
              "GET           30473\n",
              "POST           1212\n",
              "TRACE           387\n",
              "OPTIONS           6\n",
              "PROPFIND          4\n",
              "PUT               2\n",
              "SEARCH            2\n",
              "Name: http.request.method, dtype: int64"
            ]
          },
          "metadata": {},
          "execution_count": 16
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "df['http.referer'].value_counts() "
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "XUQwQuQbHVZr",
        "outputId": "1a5d2760-6bc3-4621-cb1b-b8addac25af4"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "0.0                                                                     1796035\n",
              "0                                                                        113066\n",
              "127.0.0.1                                                                   383\n",
              "() { _; } >_[$($())] { echo 93e4r0-CVE-2014-6278: true; echo;echo; }        185\n",
              "TESTING_PURPOSES_ONLY                                                         2\n",
              "Name: http.referer, dtype: int64"
            ]
          },
          "metadata": {},
          "execution_count": 17
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "df['http.request.version'].value_counts() "
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "mPDJxGmRHexz",
        "outputId": "9c05d722-867e-45a3-ff7e-c89008f42869"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "0.0                                                                                1658111\n",
              "0                                                                                   219474\n",
              "HTTP/1.1                                                                             28681\n",
              "HTTP/1.0                                                                              3382\n",
              "-a HTTP/1.1                                                                              4\n",
              "Src=javascript:alert('Vulnerable')><Img Src=\\\" HTTP/1.1                                  4\n",
              "-al&ABSOLUTE_PATH_STUDIP=http://cirt.net/rfiinc.txt?? HTTP/1.1                           3\n",
              "script>alert(1)/script><\\\" HTTP/1.1                                                      3\n",
              "-al&_PHPLIB[libdir]=http://cirt.net/rfiinc.txt?? HTTP/1.1                                2\n",
              "> HTTP/1.1                                                                               2\n",
              "/etc/passwd|?data=Download HTTP/1.1                                                      2\n",
              "name=a><input name=i value=XSS>&lt;script>alert('Vulnerable')</script> HTTP/1.1          2\n",
              "By Dr HTTP/1.1                                                                           1\n",
              "Name: http.request.version, dtype: int64"
            ]
          },
          "metadata": {},
          "execution_count": 18
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "df['dns.qry.name.len'].value_counts() "
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "G2TgAoBTH1-q",
        "outputId": "96ac2d7f-5243-4932-ff70-90b96233f421"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "0                         1362163\n",
              "0.0                        545446\n",
              "0.debian.pool.ntp.org         450\n",
              "3.debian.pool.ntp.org         448\n",
              "2.debian.pool.ntp.org         444\n",
              "1.debian.pool.ntp.org         443\n",
              "1.0                           227\n",
              "raspberrypi.local              38\n",
              "_googlecast._tcp.local          6\n",
              "null-null.local                 6\n",
              "Name: dns.qry.name.len, dtype: int64"
            ]
          },
          "metadata": {},
          "execution_count": 19
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "df['mqtt.conack.flags'].value_counts()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "sA4DFhWAIFIL",
        "outputId": "9affc7fc-b477-4903-8007-a58b0c17aa97"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "0             1280941\n",
              "0.0            545673\n",
              "0x00000000      83017\n",
              "1574358             9\n",
              "1574359             9\n",
              "1461383             4\n",
              "1461384             4\n",
              "1461589             3\n",
              "1461591             3\n",
              "1461074             2\n",
              "1471198             2\n",
              "1471199             2\n",
              "1461073             2\n",
              "Name: mqtt.conack.flags, dtype: int64"
            ]
          },
          "metadata": {},
          "execution_count": 20
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "df['mqtt.protoname'].value_counts()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "vuPCa6ahIa2j",
        "outputId": "89b36368-a34d-450f-8397-ed9130b63cb7"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "0       1280980\n",
              "0.0      545673\n",
              "MQTT      83018\n",
              "Name: mqtt.protoname, dtype: int64"
            ]
          },
          "metadata": {},
          "execution_count": 21
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "df['mqtt.topic'].value_counts()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "X_0nHC4pIk2k",
        "outputId": "3e64056a-f3bf-41a3-a46b-2a22e6867e65"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "0                           1280983\n",
              "0.0                          545673\n",
              "Temperature_and_Humidity      83015\n",
              "Name: mqtt.topic, dtype: int64"
            ]
          },
          "metadata": {},
          "execution_count": 22
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "**Apply Dummy Encoding for Text**"
      ],
      "metadata": {
        "id": "3QewONGvJc0c"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "import numpy as np\n",
        "\n",
        "from sklearn.model_selection import train_test_split\n",
        "\n",
        "from sklearn.preprocessing import StandardScaler\n",
        "\n",
        "from sklearn import preprocessing\n",
        "\n",
        "def encode_text_dummy(df, name):\n",
        "\n",
        "    dummies = pd.get_dummies(df[name])\n",
        "\n",
        "    for x in dummies.columns:\n",
        "\n",
        "        dummy_name = f\"{name}-{x}\"\n",
        "\n",
        "        df[dummy_name] = dummies[x]\n",
        "\n",
        "    df.drop(name, axis=1, inplace=True)\n",
        "\n",
        "encode_text_dummy(df,'http.request.method')\n",
        "\n",
        "encode_text_dummy(df,'http.referer')\n",
        "\n",
        "encode_text_dummy(df,\"http.request.version\")\n",
        "\n",
        "encode_text_dummy(df,\"dns.qry.name.len\")\n",
        "\n",
        "encode_text_dummy(df,\"mqtt.conack.flags\")\n",
        "\n",
        "encode_text_dummy(df,\"mqtt.protoname\")\n",
        "\n",
        "encode_text_dummy(df,\"mqtt.topic\")"
      ],
      "metadata": {
        "id": "LrpPW3AvJjuH"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "df.head()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 317
        },
        "id": "NvR9WNpQJrgf",
        "outputId": "eb82cd42-9ce9-4af3-e217-f463ab9a6022"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "         arp.opcode  arp.hw.size  icmp.checksum  icmp.seq_le  icmp.unused  \\\n",
              "1860485         0.0          0.0            0.0          0.0          0.0   \n",
              "1526476         0.0          0.0            0.0          0.0          0.0   \n",
              "1796404         0.0          0.0            0.0          0.0          0.0   \n",
              "143399          0.0          0.0            0.0          0.0          0.0   \n",
              "859515          0.0          0.0            0.0          0.0          0.0   \n",
              "\n",
              "         http.content_length  http.response  http.tls_port       tcp.ack  \\\n",
              "1860485                  0.0            0.0            0.0  8.700000e+01   \n",
              "1526476                  0.0            0.0            0.0  1.000000e+00   \n",
              "1796404                  0.0            0.0            0.0  1.069571e+09   \n",
              "143399                   0.0            0.0            0.0  0.000000e+00   \n",
              "859515                   0.0            0.0            0.0  5.900000e+01   \n",
              "\n",
              "          tcp.ack_raw  ...  mqtt.conack.flags-1471198  \\\n",
              "1860485  1.093946e+09  ...                          0   \n",
              "1526476  4.189800e+09  ...                          0   \n",
              "1796404  1.069571e+09  ...                          0   \n",
              "143399   0.000000e+00  ...                          0   \n",
              "859515   1.200409e+09  ...                          0   \n",
              "\n",
              "         mqtt.conack.flags-1471199  mqtt.conack.flags-1574358  \\\n",
              "1860485                          0                          0   \n",
              "1526476                          0                          0   \n",
              "1796404                          0                          0   \n",
              "143399                           0                          0   \n",
              "859515                           0                          0   \n",
              "\n",
              "         mqtt.conack.flags-1574359  mqtt.protoname-0  mqtt.protoname-0.0  \\\n",
              "1860485                          0                 0                   1   \n",
              "1526476                          0                 1                   0   \n",
              "1796404                          0                 0                   1   \n",
              "143399                           0                 1                   0   \n",
              "859515                           0                 1                   0   \n",
              "\n",
              "         mqtt.protoname-MQTT  mqtt.topic-0  mqtt.topic-0.0  \\\n",
              "1860485                    0             0               1   \n",
              "1526476                    0             1               0   \n",
              "1796404                    0             0               1   \n",
              "143399                     0             1               0   \n",
              "859515                     0             1               0   \n",
              "\n",
              "         mqtt.topic-Temperature_and_Humidity  \n",
              "1860485                                    0  \n",
              "1526476                                    0  \n",
              "1796404                                    0  \n",
              "143399                                     0  \n",
              "859515                                     0  \n",
              "\n",
              "[5 rows x 96 columns]"
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-ffede922-4fe9-4e0c-8c80-bf4d369611b4\">\n",
              "    <div class=\"colab-df-container\">\n",
              "      <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>arp.opcode</th>\n",
              "      <th>arp.hw.size</th>\n",
              "      <th>icmp.checksum</th>\n",
              "      <th>icmp.seq_le</th>\n",
              "      <th>icmp.unused</th>\n",
              "      <th>http.content_length</th>\n",
              "      <th>http.response</th>\n",
              "      <th>http.tls_port</th>\n",
              "      <th>tcp.ack</th>\n",
              "      <th>tcp.ack_raw</th>\n",
              "      <th>...</th>\n",
              "      <th>mqtt.conack.flags-1471198</th>\n",
              "      <th>mqtt.conack.flags-1471199</th>\n",
              "      <th>mqtt.conack.flags-1574358</th>\n",
              "      <th>mqtt.conack.flags-1574359</th>\n",
              "      <th>mqtt.protoname-0</th>\n",
              "      <th>mqtt.protoname-0.0</th>\n",
              "      <th>mqtt.protoname-MQTT</th>\n",
              "      <th>mqtt.topic-0</th>\n",
              "      <th>mqtt.topic-0.0</th>\n",
              "      <th>mqtt.topic-Temperature_and_Humidity</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>1860485</th>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>8.700000e+01</td>\n",
              "      <td>1.093946e+09</td>\n",
              "      <td>...</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1526476</th>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>1.000000e+00</td>\n",
              "      <td>4.189800e+09</td>\n",
              "      <td>...</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1796404</th>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>1.069571e+09</td>\n",
              "      <td>1.069571e+09</td>\n",
              "      <td>...</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>143399</th>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.000000e+00</td>\n",
              "      <td>0.000000e+00</td>\n",
              "      <td>...</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>859515</th>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>5.900000e+01</td>\n",
              "      <td>1.200409e+09</td>\n",
              "      <td>...</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "<p>5 rows × 96 columns</p>\n",
              "</div>\n",
              "      <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-ffede922-4fe9-4e0c-8c80-bf4d369611b4')\"\n",
              "              title=\"Convert this dataframe to an interactive table.\"\n",
              "              style=\"display:none;\">\n",
              "        \n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "       width=\"24px\">\n",
              "    <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
              "    <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
              "  </svg>\n",
              "      </button>\n",
              "      \n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      flex-wrap:wrap;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "      <script>\n",
              "        const buttonEl =\n",
              "          document.querySelector('#df-ffede922-4fe9-4e0c-8c80-bf4d369611b4 button.colab-df-convert');\n",
              "        buttonEl.style.display =\n",
              "          google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "        async function convertToInteractive(key) {\n",
              "          const element = document.querySelector('#df-ffede922-4fe9-4e0c-8c80-bf4d369611b4');\n",
              "          const dataTable =\n",
              "            await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                     [key], {});\n",
              "          if (!dataTable) return;\n",
              "\n",
              "          const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "            '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "            + ' to learn more about interactive tables.';\n",
              "          element.innerHTML = '';\n",
              "          dataTable['output_type'] = 'display_data';\n",
              "          await google.colab.output.renderOutput(dataTable, element);\n",
              "          const docLink = document.createElement('div');\n",
              "          docLink.innerHTML = docLinkHtml;\n",
              "          element.appendChild(docLink);\n",
              "        }\n",
              "      </script>\n",
              "    </div>\n",
              "  </div>\n",
              "  "
            ]
          },
          "metadata": {},
          "execution_count": 24
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "df.shape"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "QHi8VU7OJ6s8",
        "outputId": "d1ec6d6c-9653-4f58-ce47-1ecd37781c72"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "(1909671, 96)"
            ]
          },
          "metadata": {},
          "execution_count": 25
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "**Move Attack_Type at the End**"
      ],
      "metadata": {
        "id": "4y9XnL-XNR6H"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "cols = list(df.columns.values)\n",
        "cols.pop(cols.index('Attack_type'))\n",
        "df = df[cols+['Attack_type']]"
      ],
      "metadata": {
        "id": "OAKd6RuzNXyF"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "df.head()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 317
        },
        "id": "RmKilbpwN8FT",
        "outputId": "d3022660-1004-4834-b95d-30a82f676033"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "         arp.opcode  arp.hw.size  icmp.checksum  icmp.seq_le  icmp.unused  \\\n",
              "1860485         0.0          0.0            0.0          0.0          0.0   \n",
              "1526476         0.0          0.0            0.0          0.0          0.0   \n",
              "1796404         0.0          0.0            0.0          0.0          0.0   \n",
              "143399          0.0          0.0            0.0          0.0          0.0   \n",
              "859515          0.0          0.0            0.0          0.0          0.0   \n",
              "\n",
              "         http.content_length  http.response  http.tls_port       tcp.ack  \\\n",
              "1860485                  0.0            0.0            0.0  8.700000e+01   \n",
              "1526476                  0.0            0.0            0.0  1.000000e+00   \n",
              "1796404                  0.0            0.0            0.0  1.069571e+09   \n",
              "143399                   0.0            0.0            0.0  0.000000e+00   \n",
              "859515                   0.0            0.0            0.0  5.900000e+01   \n",
              "\n",
              "          tcp.ack_raw  ...  mqtt.conack.flags-1471199  \\\n",
              "1860485  1.093946e+09  ...                          0   \n",
              "1526476  4.189800e+09  ...                          0   \n",
              "1796404  1.069571e+09  ...                          0   \n",
              "143399   0.000000e+00  ...                          0   \n",
              "859515   1.200409e+09  ...                          0   \n",
              "\n",
              "         mqtt.conack.flags-1574358  mqtt.conack.flags-1574359  \\\n",
              "1860485                          0                          0   \n",
              "1526476                          0                          0   \n",
              "1796404                          0                          0   \n",
              "143399                           0                          0   \n",
              "859515                           0                          0   \n",
              "\n",
              "         mqtt.protoname-0  mqtt.protoname-0.0  mqtt.protoname-MQTT  \\\n",
              "1860485                 0                   1                    0   \n",
              "1526476                 1                   0                    0   \n",
              "1796404                 0                   1                    0   \n",
              "143399                  1                   0                    0   \n",
              "859515                  1                   0                    0   \n",
              "\n",
              "         mqtt.topic-0  mqtt.topic-0.0  mqtt.topic-Temperature_and_Humidity  \\\n",
              "1860485             0               1                                    0   \n",
              "1526476             1               0                                    0   \n",
              "1796404             0               1                                    0   \n",
              "143399              1               0                                    0   \n",
              "859515              1               0                                    0   \n",
              "\n",
              "         Attack_type  \n",
              "1860485     Password  \n",
              "1526476       Normal  \n",
              "1796404     DDoS_TCP  \n",
              "143399        Normal  \n",
              "859515        Normal  \n",
              "\n",
              "[5 rows x 96 columns]"
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-6bee2075-ee5e-4a3e-abec-287203d2794f\">\n",
              "    <div class=\"colab-df-container\">\n",
              "      <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>arp.opcode</th>\n",
              "      <th>arp.hw.size</th>\n",
              "      <th>icmp.checksum</th>\n",
              "      <th>icmp.seq_le</th>\n",
              "      <th>icmp.unused</th>\n",
              "      <th>http.content_length</th>\n",
              "      <th>http.response</th>\n",
              "      <th>http.tls_port</th>\n",
              "      <th>tcp.ack</th>\n",
              "      <th>tcp.ack_raw</th>\n",
              "      <th>...</th>\n",
              "      <th>mqtt.conack.flags-1471199</th>\n",
              "      <th>mqtt.conack.flags-1574358</th>\n",
              "      <th>mqtt.conack.flags-1574359</th>\n",
              "      <th>mqtt.protoname-0</th>\n",
              "      <th>mqtt.protoname-0.0</th>\n",
              "      <th>mqtt.protoname-MQTT</th>\n",
              "      <th>mqtt.topic-0</th>\n",
              "      <th>mqtt.topic-0.0</th>\n",
              "      <th>mqtt.topic-Temperature_and_Humidity</th>\n",
              "      <th>Attack_type</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>1860485</th>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>8.700000e+01</td>\n",
              "      <td>1.093946e+09</td>\n",
              "      <td>...</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>Password</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1526476</th>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>1.000000e+00</td>\n",
              "      <td>4.189800e+09</td>\n",
              "      <td>...</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>Normal</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1796404</th>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>1.069571e+09</td>\n",
              "      <td>1.069571e+09</td>\n",
              "      <td>...</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>DDoS_TCP</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>143399</th>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.000000e+00</td>\n",
              "      <td>0.000000e+00</td>\n",
              "      <td>...</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>Normal</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>859515</th>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>5.900000e+01</td>\n",
              "      <td>1.200409e+09</td>\n",
              "      <td>...</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>Normal</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "<p>5 rows × 96 columns</p>\n",
              "</div>\n",
              "      <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-6bee2075-ee5e-4a3e-abec-287203d2794f')\"\n",
              "              title=\"Convert this dataframe to an interactive table.\"\n",
              "              style=\"display:none;\">\n",
              "        \n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "       width=\"24px\">\n",
              "    <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
              "    <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
              "  </svg>\n",
              "      </button>\n",
              "      \n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      flex-wrap:wrap;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "      <script>\n",
              "        const buttonEl =\n",
              "          document.querySelector('#df-6bee2075-ee5e-4a3e-abec-287203d2794f button.colab-df-convert');\n",
              "        buttonEl.style.display =\n",
              "          google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "        async function convertToInteractive(key) {\n",
              "          const element = document.querySelector('#df-6bee2075-ee5e-4a3e-abec-287203d2794f');\n",
              "          const dataTable =\n",
              "            await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                     [key], {});\n",
              "          if (!dataTable) return;\n",
              "\n",
              "          const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "            '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "            + ' to learn more about interactive tables.';\n",
              "          element.innerHTML = '';\n",
              "          dataTable['output_type'] = 'display_data';\n",
              "          await google.colab.output.renderOutput(dataTable, element);\n",
              "          const docLink = document.createElement('div');\n",
              "          docLink.innerHTML = docLinkHtml;\n",
              "          element.appendChild(docLink);\n",
              "        }\n",
              "      </script>\n",
              "    </div>\n",
              "  </div>\n",
              "  "
            ]
          },
          "metadata": {},
          "execution_count": 31
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "df.info()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "2380b19e-d885-4c6b-b9bd-2cc9eaa98973",
        "id": "zF-o6OaXKtqx"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "<class 'pandas.core.frame.DataFrame'>\n",
            "Int64Index: 1909671 entries, 1860485 to 1293281\n",
            "Data columns (total 96 columns):\n",
            " #   Column                                                                                                Dtype  \n",
            "---  ------                                                                                                -----  \n",
            " 0   arp.opcode                                                                                            float64\n",
            " 1   arp.hw.size                                                                                           float64\n",
            " 2   icmp.checksum                                                                                         float64\n",
            " 3   icmp.seq_le                                                                                           float64\n",
            " 4   icmp.unused                                                                                           float64\n",
            " 5   http.content_length                                                                                   float64\n",
            " 6   http.response                                                                                         float64\n",
            " 7   http.tls_port                                                                                         float64\n",
            " 8   tcp.ack                                                                                               float64\n",
            " 9   tcp.ack_raw                                                                                           float64\n",
            " 10  tcp.checksum                                                                                          float64\n",
            " 11  tcp.connection.fin                                                                                    float64\n",
            " 12  tcp.connection.rst                                                                                    float64\n",
            " 13  tcp.connection.syn                                                                                    float64\n",
            " 14  tcp.connection.synack                                                                                 float64\n",
            " 15  tcp.flags                                                                                             float64\n",
            " 16  tcp.flags.ack                                                                                         float64\n",
            " 17  tcp.len                                                                                               float64\n",
            " 18  tcp.seq                                                                                               float64\n",
            " 19  udp.stream                                                                                            float64\n",
            " 20  udp.time_delta                                                                                        float64\n",
            " 21  dns.qry.name                                                                                          float64\n",
            " 22  dns.qry.qu                                                                                            float64\n",
            " 23  dns.qry.type                                                                                          float64\n",
            " 24  dns.retransmission                                                                                    float64\n",
            " 25  dns.retransmit_request                                                                                float64\n",
            " 26  dns.retransmit_request_in                                                                             float64\n",
            " 27  mqtt.conflag.cleansess                                                                                float64\n",
            " 28  mqtt.conflags                                                                                         float64\n",
            " 29  mqtt.hdrflags                                                                                         float64\n",
            " 30  mqtt.len                                                                                              float64\n",
            " 31  mqtt.msg_decoded_as                                                                                   float64\n",
            " 32  mqtt.msgtype                                                                                          float64\n",
            " 33  mqtt.proto_len                                                                                        float64\n",
            " 34  mqtt.topic_len                                                                                        float64\n",
            " 35  mqtt.ver                                                                                              float64\n",
            " 36  mbtcp.len                                                                                             float64\n",
            " 37  mbtcp.trans_id                                                                                        float64\n",
            " 38  mbtcp.unit_id                                                                                         float64\n",
            " 39  http.request.method-0                                                                                 uint8  \n",
            " 40  http.request.method-0.0                                                                               uint8  \n",
            " 41  http.request.method-GET                                                                               uint8  \n",
            " 42  http.request.method-OPTIONS                                                                           uint8  \n",
            " 43  http.request.method-POST                                                                              uint8  \n",
            " 44  http.request.method-PROPFIND                                                                          uint8  \n",
            " 45  http.request.method-PUT                                                                               uint8  \n",
            " 46  http.request.method-SEARCH                                                                            uint8  \n",
            " 47  http.request.method-TRACE                                                                             uint8  \n",
            " 48  http.referer-() { _; } >_[$($())] { echo 93e4r0-CVE-2014-6278: true; echo;echo; }                     uint8  \n",
            " 49  http.referer-0                                                                                        uint8  \n",
            " 50  http.referer-0.0                                                                                      uint8  \n",
            " 51  http.referer-127.0.0.1                                                                                uint8  \n",
            " 52  http.referer-TESTING_PURPOSES_ONLY                                                                    uint8  \n",
            " 53  http.request.version--a HTTP/1.1                                                                      uint8  \n",
            " 54  http.request.version--al&ABSOLUTE_PATH_STUDIP=http://cirt.net/rfiinc.txt?? HTTP/1.1                   uint8  \n",
            " 55  http.request.version--al&_PHPLIB[libdir]=http://cirt.net/rfiinc.txt?? HTTP/1.1                        uint8  \n",
            " 56  http.request.version-/etc/passwd|?data=Download HTTP/1.1                                              uint8  \n",
            " 57  http.request.version-0                                                                                uint8  \n",
            " 58  http.request.version-0.0                                                                              uint8  \n",
            " 59  http.request.version-> HTTP/1.1                                                                       uint8  \n",
            " 60  http.request.version-By Dr HTTP/1.1                                                                   uint8  \n",
            " 61  http.request.version-HTTP/1.0                                                                         uint8  \n",
            " 62  http.request.version-HTTP/1.1                                                                         uint8  \n",
            " 63  http.request.version-Src=javascript:alert('Vulnerable')><Img Src=\\\" HTTP/1.1                          uint8  \n",
            " 64  http.request.version-name=a><input name=i value=XSS>&lt;script>alert('Vulnerable')</script> HTTP/1.1  uint8  \n",
            " 65  http.request.version-script>alert(1)/script><\\\" HTTP/1.1                                              uint8  \n",
            " 66  dns.qry.name.len-0                                                                                    uint8  \n",
            " 67  dns.qry.name.len-0.0                                                                                  uint8  \n",
            " 68  dns.qry.name.len-0.debian.pool.ntp.org                                                                uint8  \n",
            " 69  dns.qry.name.len-1.0                                                                                  uint8  \n",
            " 70  dns.qry.name.len-1.debian.pool.ntp.org                                                                uint8  \n",
            " 71  dns.qry.name.len-2.debian.pool.ntp.org                                                                uint8  \n",
            " 72  dns.qry.name.len-3.debian.pool.ntp.org                                                                uint8  \n",
            " 73  dns.qry.name.len-_googlecast._tcp.local                                                               uint8  \n",
            " 74  dns.qry.name.len-null-null.local                                                                      uint8  \n",
            " 75  dns.qry.name.len-raspberrypi.local                                                                    uint8  \n",
            " 76  mqtt.conack.flags-0                                                                                   uint8  \n",
            " 77  mqtt.conack.flags-0.0                                                                                 uint8  \n",
            " 78  mqtt.conack.flags-0x00000000                                                                          uint8  \n",
            " 79  mqtt.conack.flags-1461073                                                                             uint8  \n",
            " 80  mqtt.conack.flags-1461074                                                                             uint8  \n",
            " 81  mqtt.conack.flags-1461383                                                                             uint8  \n",
            " 82  mqtt.conack.flags-1461384                                                                             uint8  \n",
            " 83  mqtt.conack.flags-1461589                                                                             uint8  \n",
            " 84  mqtt.conack.flags-1461591                                                                             uint8  \n",
            " 85  mqtt.conack.flags-1471198                                                                             uint8  \n",
            " 86  mqtt.conack.flags-1471199                                                                             uint8  \n",
            " 87  mqtt.conack.flags-1574358                                                                             uint8  \n",
            " 88  mqtt.conack.flags-1574359                                                                             uint8  \n",
            " 89  mqtt.protoname-0                                                                                      uint8  \n",
            " 90  mqtt.protoname-0.0                                                                                    uint8  \n",
            " 91  mqtt.protoname-MQTT                                                                                   uint8  \n",
            " 92  mqtt.topic-0                                                                                          uint8  \n",
            " 93  mqtt.topic-0.0                                                                                        uint8  \n",
            " 94  mqtt.topic-Temperature_and_Humidity                                                                   uint8  \n",
            " 95  Attack_type                                                                                           object \n",
            "dtypes: float64(39), object(1), uint8(56)\n",
            "memory usage: 699.3+ MB\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "**Export Complete Preprocessed Dataset**"
      ],
      "metadata": {
        "id": "vNTg5D94wCkg"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "df.to_csv('/content/drive/MyDrive/processed_IIoT.csv', encoding='utf-8', index=False)"
      ],
      "metadata": {
        "id": "JYWXEwId4d11"
      },
      "execution_count": null,
      "outputs": []
    }
  ]
}